package com.jadeen.controller.clientController;


import cn.dev33.satoken.stp.StpUtil;
import com.jadeen.common.controller.BaseController;
import com.jadeen.common.domain.AjaxResult;
import com.jadeen.common.page.TableDataInfo;
import com.jadeen.entity.domain.Resource;
import com.jadeen.service.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资源Controller
 * 
 * @author jadeen
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/client/share/resource")
public class ClientResourceController extends BaseController
{
    @Autowired
    private IResourceService resourceService;

    /**
     * 查询资源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Resource resource)
    {
        System.out.println("当前会话是否登录：" + StpUtil.isLogin());

        startPage();
        List<Resource> list = resourceService.selectResourceList(resource);
        return getDataTable(list);
    }


    /**
     * 获取资源详细信息
     */
    @GetMapping(value = "/{resourceId}")
    public AjaxResult getInfo(@PathVariable("resourceId") Long resourceId)
    {
        return success(resourceService.selectResourceByResourceId(resourceId));
    }

    /**
     * 新增资源
     */
    @PostMapping
    public AjaxResult add(@RequestBody Resource resource)
    {
        return toAjax(resourceService.insertResource(resource));
    }
    /**
     * 修改资源
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Resource resource)
    {
        return toAjax(resourceService.updateResource(resource));
    }

}
